package com.atis.warplot.database.utils;

import java.security.MessageDigest;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Utils {

	// --------------------------------------------------------------------------------

	private Utils() {
		/* empty */
	}

	// --------------------------------------------------------------------------------

	public enum UnitType {
		Terrestre, Aerea, Maritima
	}

	// --------------------------------------------------------------------------------

	public static String encrypt(String password) //
			throws Exception {

		MessageDigest md = MessageDigest.getInstance("SHA");
		byte[] b = md.digest(password.getBytes());

		int size = b.length;
		StringBuffer h = new StringBuffer(size);

		for (int i = 0; i < size; i++) {

			int u = b[i] & 255;

			if (u < 16) {
				h.append("0" + Integer.toHexString(u));
			} else {
				h.append(Integer.toHexString(u));
			}

		}
		return h.toString();

	}

	// --------------------------------------------------------------------------------

	public static boolean validateMail(String mail) {

		Pattern pattern = Pattern.compile( //
				"[a-zA-Z0-9]+[.[a-zA-Z0-9_-]+]*@[a-z0-9][\\w\\.-]" +
				"*[a-z0-9]\\.[a-z][a-z\\.]*[a-z]$");
		Matcher matcher = pattern.matcher(mail);

		return matcher.matches();

	}

	// --------------------------------------------------------------------------------

}
